package cn.dnui_zjq823.dnuifood_16110100823.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dnui_zjq823.dnuifood_16110100823.R;
import cn.dnui_zjq823.dnuifood_16110100823.bean.CommentBean;

/**
 * Created by dell on 2018/12/10.
 */

public class CommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<CommentBean> list;
    private Context context;
    private String url="http://172.24.10.175:8080/foodService/";

    public CommentAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<CommentBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_item,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        final CommentBean commentBean=list.get(position);
        if (commentBean==null)
            return;
        //ViewHolder viewHolder=(ViewHolder)holder;
        CommentAdapter.ViewHolder viewHolder=(CommentAdapter.ViewHolder)holder;
        viewHolder.comment_username.setText(commentBean.getUsername());
        viewHolder.comment_main.setText(commentBean.getContent());
        viewHolder.comment_date.setText(commentBean.getComment_time());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView comment_username,comment_main,comment_date;
        public ViewHolder(View itemView) {
            super(itemView);
            comment_username=(TextView)itemView.findViewById(R.id.comment_username);
            comment_main=(TextView)itemView.findViewById(R.id.comment_main);
            comment_date=(TextView)itemView.findViewById(R.id.comment_date);

        }
    }
}
